package com.united.ucts.modules.oss.controller;

import com.united.frame.common.module.result.Result;
import com.united.frame.oss.minio.domain.MinioUploadResult;
import com.united.frame.oss.minio.service.MinioService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * MinIO对象存储管理相关操作接口
 *
 * @author Hudan
 * @version 1.0
 * @filename MinioController.java
 * @copyright <a href="www.united.cn">www.united.cn</a>
 * @date 2019-08-04
 */
@Api(tags = "MinioController", value = "MinIO对象存储管理")
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/oss/minio")
public class MinioController {

    private final MinioService minioService;

    @ApiOperation("文件上传")
    @PostMapping(value = "/upload")
    public Result<MinioUploadResult> upload(@RequestPart("file") MultipartFile file) {
        return Result.success(minioService.upload(file));
    }

    @ApiOperation("文件删除")
    @PostMapping(value = "/delete")
    public Result<Boolean> delete(@RequestParam("objectName") String objectName) {
        return Result.success(minioService.delete(objectName));
    }
}